package com.xyzq.reks.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.appfuse.model.BaseObject;
import org.appfuse.model.User;

@Entity
@Table(name = "order_sell")
public class OrderSell extends BaseObject implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3502641759977829415L;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	@Column(name = "client_id")
	private Integer clientId;
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "FK_USER_USER", nullable = false)
	private User user;
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "FK_COMPANYFUND_CODE", nullable = false)
	private CompanyFund fund;
	@Column(columnDefinition = "enum('in','out')")
	private String market;
	@Column(scale = 2)
	private Double money;
	@Temporal(TemporalType.DATE)
	@Column(name = "order_date")
	private Date orderDate;
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "sub_time")
	private Date subTime;

	public Long getId() {
		return id;
	}

	public Integer getClientId() {
		return clientId;
	}

	public CompanyFund getFund() {
		return fund;
	}

	public String getMarket() {
		return market;
	}

	public Double getMoney() {
		return money;
	}

	public Date getOrderDate() {
		return orderDate;
	}

	public Date getSubTime() {
		return subTime;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setClientId(Integer clientId) {
		this.clientId = clientId;
	}

	public void setFund(CompanyFund fund) {
		this.fund = fund;
	}

	public void setMarket(String market) {
		this.market = market;
	}

	public void setMoney(Double money) {
		this.money = money;
	}

	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}

	public void setSubTime(Date subTime) {
		this.subTime = subTime;
	}

	@Override
	public String toString() {
		ToStringBuilder builder = new ToStringBuilder(this,
				ToStringStyle.DEFAULT_STYLE);
		builder.append("id", id);
		builder.append("clientId", clientId);
		builder.append("user", user);
		builder.append("fund", fund);
		builder.append("market", market);
		builder.append("money", money);
		builder.append("orderDate", orderDate);
		builder.append("subTime", subTime);
		return builder.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((clientId == null) ? 0 : clientId.hashCode());
		result = prime * result + ((fund == null) ? 0 : fund.hashCode());
		result = prime * result + ((market == null) ? 0 : market.hashCode());
		result = prime * result + ((money == null) ? 0 : money.hashCode());
		result = prime * result
				+ ((orderDate == null) ? 0 : orderDate.hashCode());
		result = prime * result + ((subTime == null) ? 0 : subTime.hashCode());
		result = prime * result + ((user == null) ? 0 : user.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		OrderSell other = (OrderSell) obj;
		if (clientId == null) {
			if (other.clientId != null)
				return false;
		} else if (!clientId.equals(other.clientId))
			return false;
		if (fund == null) {
			if (other.fund != null)
				return false;
		} else if (!fund.equals(other.fund))
			return false;
		if (market == null) {
			if (other.market != null)
				return false;
		} else if (!market.equals(other.market))
			return false;
		if (money == null) {
			if (other.money != null)
				return false;
		} else if (!money.equals(other.money))
			return false;
		if (orderDate == null) {
			if (other.orderDate != null)
				return false;
		} else if (!orderDate.equals(other.orderDate))
			return false;
		if (subTime == null) {
			if (other.subTime != null)
				return false;
		} else if (!subTime.equals(other.subTime))
			return false;
		if (user == null) {
			if (other.user != null)
				return false;
		} else if (!user.equals(other.user))
			return false;
		return true;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public User getUser() {
		return user;
	}

}
